<template>
  <div class="app">
    <el-container>
      <el-aside class="app-side app-side-left" :class="isCollapse ? 'app-side-collapsed' : 'app-side-expanded'">
        <div class="app-side-logo">
          <img src="@/assets/logo.png" :width="isCollapse ? '60' : '60'" height="60" alt="">
        </div>
        <Sidebar :collapse="isCollapse" />
      </el-aside>

      <el-container>
        <el-header class="app-header">
          <div style="width: 60px; cursor: pointer;" @click.prevent="toggleSideBar">
            <svg-icon v-show="isCollapse" iconClass="menu-retract"></svg-icon>
            <svg-icon v-show="!isCollapse" iconClass="menu-open"></svg-icon>
          </div>
          <!-- 我是样例菜单 -->
          <!-- <el-menu default-active="/" router class="el-menu-demo tab-page" mode="horizontal" @select="handleSelect" active-text-color="#409EFF">
            <el-menu-item index="/">首页</el-menu-item>
          </el-menu> -->

          <div class="app-header-userinfo">
            <el-dropdown trigger="hover" :hide-on-click="false">
              <span class="el-dropdown-link">
                {{ username }}
                <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>我的消息</el-dropdown-item>
                <el-dropdown-item>设置</el-dropdown-item>
                <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>

        <!-- 主体内容 -->
        <section class="content-container">
          <div class="grid-content bg-purple-light">
            <el-col class="breadcrumb-container">
              <strong class="title">{{$route.name}}</strong>
              <el-breadcrumb class="breadcrumb-inner" separator="/">
                <el-breadcrumb-item v-for="item in $route.matched" :key="item.path">
                  {{ item.name }}
                </el-breadcrumb-item>
              </el-breadcrumb>
            </el-col>
            <el-col :span="24" class="content-wrapper">
              <transition name="fade" mode="out-in">
                <router-view></router-view>
              </transition>
            </el-col>
          </div>
        </section>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import Sidebar from '@/components/Sidebar'
// import SidebarItem from '@/components/SidebarItem'
export default {
  name: 'Home',
  components: {
    Sidebar
  },
  data() {
    return {
      username: '',
      isCollapse: false
    }
  },
  methods: {
    toggleSideBar() {
      this.isCollapse = !this.isCollapse
    },
    logout: function () {
      this.$confirm('确认退出?', '提示', {})
        .then(() => {
          sessionStorage.removeItem('user')
          this.$router.push('/login')
        })
        .catch(() => { })
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath)
    },
  },
  computed: {
    defaultActive () {
      return this.$route.path
    },
    fatherPath () {
      return this.$router.options.routes[1].path
    }
  },
  mounted: function () {
    let user = sessionStorage.getItem('user')
    if (user) {
      this.username = user
    }
  },
}
</script>

<style lang="scss" scoped>
.app {
  $solidBorder: 1px solid #eee;
  font-size: 1em;
  height: 100%;
  border: $solidBorder;
  display: flex;
  display: -webkit-flex;
  flex-flow: row nowrap;
  &-side {
    width: 230px;
    height: 100%;
    font-weight: 700;
    border-right: $solidBorder;
    &-left {
      background-color: rgb(238, 241, 246);
    }
    &-logo {
      height: 60px;
      text-align: center;
    }
    &-collapsed {
      width: 66px !important;
    }
    &-expanded {
      width: 230px !important;
    }
  }
  &-header {
    width: 100%;
    height: 60px;
    display: flex;
    flex-flow: row nowrap;
    justify-content: flex-start;
    align-items: center;
    border-bottom: $solidBorder;
    &-userinfo {
      position: absolute;
      right: 0;
      margin-right: 25px;
      display: flex;
      flex-flow: row nowrap;
      height: 60px;
      justify-content: flex-start;
      align-items: center;
    }
  }
  .content-container{
    flex: 1;
    padding: 20px;
    .breadcrumb-container{
      .title{
        width: 200px;
        float: left;
        color: #475669;
      }
      .breadcrumb-inner{
        float: right;
      }
    }
    .content-wrapper{
      background-color: #fff;
      box-sizing: border-box;
      padding: 10px 0;
    }
  }
  &-body {
    font-size: 1em;
    width: 100%;
    height: 100%;
    padding: 20px;
  }
  &-footer {
    width: 100%;
    height: 60px;
  }
}
</style>
